﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace LostLib.Wikis
{
	public class WikiPage
	{
		internal WikiPage(string path)
		{
			_path = path;
			_text = new Cached<string>(() => File.ReadAllText(_path));
		}

		readonly string _path;

		public string Title
		{
			get
			{
				return Path.GetFileNameWithoutExtension(_path);
			}
		}

		public IEnumerable<DateTime> ChangeHistory
		{
			get
			{
				throw new NotImplementedException();
			}
		}

		public string this[DateTime changeTime]
		{
			get
			{
				throw new NotImplementedException();
			}
		}

		Cached<string> _text;

		public string Text
		{
			get
			{
				return _text;
			}
			set
			{
				_text = new Cached<string>(() => File.ReadAllText(_path), value);
				File.WriteAllText(_path, value);
			}
		}

		public bool Exists
		{
			get
			{
				return File.Exists(_path);
			}
		}
	}
}
